use([
    "public/javascripts/service/notificationService.js",
    "public/javascripts/widget/slider/slider.js",
], function(notificationService, SliderComponent) {
    var PageComponent = React.createClass({
        restData:{
            'q':'',
            'isAsc': false,
            'pageIndex':1,
            'pageSize':10
        },
        componentDidMount: function() {

        },
        receiveMsg: function(data) {

        },
        getInitialState: function () {
            return this.props.data ? this.props.data : {};
        },
        render:function() {
            var data = this.state.data;
            
            var  _this = this,
                Browser = typeof window != 'undefined',
                list = this.state.list ? this.state.list : [],
                pageIndex = this.state.pageIndex ? this.state.pageIndex : 1,
                totalResult = this.state.totalResult ? this.state.totalResult : 0;
            
            return ~init;
        },
        search: function(isReset){
            var _this = this;

            _this.restData.q = $('#search').val();

            isReset ? _this.restData.pageIndex = 1 : '';

            var config = {
                'urlParams':{
                    'q':_this.restData.q,
                    'isAsc': false,
                    'pageIndex':_this.restData.pageIndex,
                    'pageSize':_this.restData.pageSize
                }
            };

            notificationService.getNoticeList(config, function (res) {
                if(res.errorCode === 0){
                    _this.refresh(res);
                }
            });
        },
        refresh: function(res){
            var _this = this,
                data = res.data,
                arr = [];

            for(var i=0, l=data.length; i<l; i++){
                arr.push(data[i]);
            }
            _this.setState({list:arr,'totalResult':res.pagination.totalResult,'pageIndex':_this.restData.pageIndex});
        },
        enter: function(){
            var _this = this;

            if(event.keyCode != 13){
                return;
            }

            _this.search(true);
        },
        onPageChange: function(pageIndex,pageSize){
            var _this = this;

            _this.restData.pageIndex = pageIndex;
            _this.restData.pageSize = pageSize;

            _this.search();
        },
        setMsgStatus: function(id) {
            var list = [];
            list.push(id);
            notificationService.setMsgStatus(list, function(res) {
                if (res.errorCode === 0) {
                    window.location.assign('/notification_info?id=' + id);
                }
            })
        }
    });
    if(typeof ReactDOM != "undefined") {
        ReactDOM.render(<PageComponent data={storage}/>, document.getElementById('container'));
    }
    module.exports = PageComponent;
});